#!/bin/bash

cwd=$(pwd)

parent_res_path=$1
local_res_path=$2
rsync_res_path=$3
local_parent_res_path=$4

#例如：parent_res_path:asr.core.sed; local_res_path:sed_res; rsync_res_path:sed_v0.1_pb,local_parent_res_path:asr.core.sed;
echo "parent_res_path: $1,local_res_path: $2, rsync_res_path: $3,local_parent_res_path: $4"


RES_ROOT_LOCAL=/data/resources/resource/$local_parent_res_path

rsync_server=$RSYNC_SERVER
if [[ $NODENAME == d3* ]]; then
  rsync_server=$D3_RSYNC_SERVER
fi

# 同步转写资源($rsync_res_path)到宿主机
echo "rsync -rptDL $rsync_server::dui_resource/$parent_res_path/$rsync_res_path $RES_ROOT_LOCAL"
rsync -rptDL --progress $rsync_server::dui_resource/$parent_res_path/$rsync_res_path $RES_ROOT_LOCAL
if [ $? -ne 0 ]; then
  echo "rsync -rptDL $rsync_server::dui_resource/$parent_res_path/$rsync_res_path $RES_ROOT_LOCAL Failed"
  exit 1
fi

#建个资源的软链到$local_res_path, For JAVA
[[ -d $RES_ROOT_LOCAL/$local_res_path ]] && rm -rf $RES_ROOT_LOCAL/$local_res_path
ln -s $RES_ROOT_LOCAL/$rsync_res_path $RES_ROOT_LOCAL/$local_res_path